<template>
  <div id="app">
    <router-view />
  </div>
</template>

<script>
export default {
  mounted() {
    // 关闭浏览器窗口的时候清空浏览器缓存在localStorage的数据
    let that = this;
    window.onbeforeunload = function (e) {
      if (!that.getCookie('JWT_TOKEN')) {
        //清除
        window.localStorage.clear();
      }
    }
  },
  methods: {
    //取得cookie    
    getCookie(name) {
      var nameEQ = name + "=";
      var ca = document.cookie.split(';'); //把cookie分割成组    
      for (var i = 0; i < ca.length; i++) {
        var c = ca[i]; //取得字符串    
        while (c.charAt(0) == ' ') { //判断一下字符串有没有前导空格    
          c = c.substring(1, c.length); //有的话，从第二位开始取    
        }
        if (c.indexOf(nameEQ) == 0) { //如果含有我们要的name    
          return unescape(c.substring(nameEQ.length, c.length)); //解码并截取我们要值    
        }
      }
      return false;
    }
  }
}
</script>

<style></style>
